import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '服务面板',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '系统', icon: 'dashboard' }
    }]
  },

  {
    path: '/user',
    component: Layout,
    redirect: '/user/index',
    name: '用户菜单',
    meta: {
      title: '用户菜单',
      icon: 'user'
    },
    children: [
      {
        path: '/user/list',
        component: () => import('@/views/user/list'),
        name: '用户管理',
        meta: { title: '用户管理' }
      },
      {
        path: '/user/info',
        component: () => import('@/views/user/info'),
        name: '用户创建',
        meta: { title: '用户创建' }
      },
      {
        path: '/user/info/:id',
        name: '用户修改',
        component: () => import('@/views/user/info'),
        meta: { title: '用户修改', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/shop',
    component: Layout,
    redirect: '/shop/list',
    name: '店铺菜单',
    meta: {
      title: '店铺菜单',
      icon: 'shop'
    },
    children: [
      {
        path: '/shop/list',
        component: () => import('@/views/shop/list'),
        name: '店铺管理',
        meta: { title: '店铺管理' }
      },
      {
        path: '/shop/info',
        component: () => import('@/views/shop/info'),
        name: '店铺创建',
        meta: { title: '店铺创建' }
      },
      {
        path: '/shop/info/:id',
        name: '店铺修改',
        component: () => import('@/views/shop/info'),
        meta: { title: '店铺修改', noCache: true },
        hidden: true
      },
      {
        path: '/shopService/info',
        name: '店铺业务',
        component: () => import('@/views/shopService/info'),
        meta: { title: '店铺业务'}
      },
    ]
  },
  {
    path: '/goodsType',
    component: Layout,
    redirect: '/goodsType/info',
    name: '商品类别',
    children: [{
      path: '/goodsType/info',
      name: '类别设置',
      component: () => import('@/views/goodsType/info'),
      meta: { title: '类别', icon: 'goodsType' }
    }]
  },
  {
    path: '/goods',
    component: Layout,
    redirect: '/goods/list',
    name: '商品菜单',
    meta: {
      title: '商品菜单',
      icon: 'goods'
    },
    children: [
      {
        path: '/goods/list',
        component: () => import('@/views/goods/list'),
        name: '商品列表',
        meta: { title: '商品列表' }
      },
      {
        path: '/goods/info',
        component: () => import('@/views/goods/info'),
        name: '商品创建',
        meta: { title: '商品创建' }
      },
      {
        path: '/goods/info/:id',
        name: '商品修改',
        component: () => import('@/views/goods/info'),
        meta: { title: '商品修改', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/indexManager',
    component: Layout,
    redirect: '/indexManager',
    name: '首页管理',
    children: [{
      path: '/indexManager/info',
      name: '首页管理',
      component: () => import('@/views/indexManager/info'),
      meta: { title: '主页推荐', icon: 'indexManager' }
    }]
  },
  {
    path: '/orderManager',
    component: Layout,
    redirect: '/orderManager',
    name: '订单管理',
    children: [
      {
        path: '/orderManager/list',
        name: '订单列表',
        component: () => import('@/views/orderManager/list'),
        meta: { title: '订单列表', icon: 'order' }
      },{
        path: '/orderManager/info/:id',
        name: '订单处理',
        component: () => import('@/views/orderManager/info'),
        meta: { title: '订单处理', noCache: true },
        hidden: true
      },
  ]
  },
  // {
  //   path: '/shopService',
  //   component: Layout,
  //   redirect: '/shopService',
  //   name: '店铺业务',
  //   children: [{
  //     path: '/shopService/info',
  //     name: '店铺业务',
  //     component: () => import('@/views/shopService/info'),
  //     meta: { title: '店铺业务', icon: 'shopservice' }
  //   }]
  // },
  
  

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
